﻿@using Stamp_For_Africa_Version_2.Helpers
@model Stamp_For_Africa_Version_2.Models.Watermark

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("/uploadify/swfobject.js")" type="text/javascript"></script>
<script src="@Url.Content("/uploadify/jquery.uploadify.v2.1.4.min.js")" type="text/javascript"></script>
<link href="@Url.Content("/uploadify/uploadify.css")" rel="stylesheet" type="text/css" />


<script type="text/javascript">


	$(function () {

		// Uploadify File Upload System
		// SessionSync data is sent in scriptData for security reasons, see UploadifySessionSync() in global.asax

		var UploadifyAuthCookie = '@(Request.Cookies[FormsAuthentication.FormsCookieName] == null ? "" : Request.Cookies[FormsAuthentication.FormsCookieName].Value)';
		var UploadifySessionId = '@Session.SessionID';

		$("#fuFileUploader").uploadify({

			'hideButton': true,       // We use a trick below to overlay a fake html upload button with this hidden flash button                         
			'wmode': 'transparent',
			'uploader': '@Url.Content("/uploadify/uploadify.swf")',
			'cancelImg': '@Url.Content("/uploadify/cancel.png")',
			'buttonText': 'Upload Watermark',
			'script': '@Url.Action("FileUpload", "Watermark")',
			'multi': false,
			'auto': true,
			'scriptData': { RequireUploadifySessionSync: true, SecurityToken: UploadifyAuthCookie, SessionId: UploadifySessionId },
			'onComplete': function (event, ID, fileObj, response, data) {
				response = $.parseJSON(response);
				if (response.Status == 'OK') {

					$("#UploadedFileName").val(response.returnFile);
					$("#NonRootedUploadedFileName").val(response.serverPath);
					$("#WatermarkImage").attr("src", response.serverPath);
					// Put your own handler code here instead of the following...
					$("#dialogUploadWatermark").dialog("close");
				}
			},
			'onError': function (event, queueID, fileObj, errorObj) {
				alert("Error!!! Type: [" + errorObj.type + "] Info [" + errorObj.info + "]");
			}
		});
	});


	function showUploadWatermarkDialog() {
		$("#dialogUploadWatermark").dialog();
		return false;
	}	
	
</script>

@*
  -----------------------------------------------------------------------
  Upload Stamp dialog
  -----------------------------------------------------------------------
*@
<div style="display: none;" id="dialogUploadWatermark" title="Upload Watermark">

		<div style="position: relative;">
        
        <input type="button" id="btnUpload" value="Upload File" />

        <div style="position: absolute; top: 4px; left: 3px;">
            <input id="fuFileUploader" name="file_upload" type="file" />
        </div>
    </div>

</div>


@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Watermark</legend>
        @Html.HiddenFor(model => model.UploadedFileName)
				<a href="" onclick="return showUploadWatermarkDialog()">Select the Watermark Image</a>
        @{
          
            <img id="WatermarkImage" src=@Model.NonRootedUploadedFileName alt="" />
          
          
        }
        <div class="editor-label">
            @Html.LabelFor(model => model.DisplayName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DisplayName)
            @Html.ValidationMessageFor(model => model.DisplayName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Description)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Description)
            @Html.ValidationMessageFor(model => model.Description)
        </div>

        <div>
          @Html.DropDownListFor(model => model.CountryId, ListHelpers.Countries)
        </div>
        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
